package com.moter.bigdata.spider;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;
import java.util.Set;

public class SeleniumDemo {
    public static void main(String[] args) {
//        System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
//        WebDriver driver = new ChromeDriver();
//        driver.get("https://www.zhipin.com/c101270100/?query=Java");
//        List<WebElement> elements1 = driver.findElements(By.xpath("//div[@class='job-list']/ul/li"));
//        System.out.println(elements1.size());
//        for (WebElement webElement : elements1) {
//            System.out.println(webElement.getText());
//        }
//        List<WebElement> elements = driver.findElements(By.className("primary-box"));
//        for (WebElement element : elements) {
//            System.out.println(element.getText());
//        }
//
//        driver.close();
        System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.jd.com/");
        WebElement element = driver.findElement(By.xpath("//*[@id=\"settleup\"]/div/a"));
        element.click();

        System.out.println(driver.getCurrentUrl());
        driver.close();
        Set<String> windowHandles = driver.getWindowHandles();
        for (String windowHandle : windowHandles) {
            driver.switchTo().window(windowHandle);
        }

        driver.findElement(By.xpath("//*[@id=\"container\"]/div[1]/div[2]/div/ul/li[2]/a[1]")).click();
        System.out.println(driver.findElement(By.xpath("//*[@id=\"loginDialogBody\"]/div[2]")).getText());
//        WebElement element1 = driver.findElement(By.xpath("//iframe[@id='dialogIframe']"));
//        driver.switchTo().frame(element);
////        System.out.println(driver.findElement(By.cssSelector("#kbCoagent > ul > li:nth-child(1) > a > span")).getText());
//        System.out.println(driver.getCurrentUrl());
//        System.out.println(driver.getPageSource().toString());

    }
}
